package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.TemplateFieldAddDTO;
import org.jsola.hr.dto.TemplateFieldUpdateDTO;
import org.jsola.hr.entity.TemplateFieldDO;
import org.jsola.hr.query.TemplateFieldQuery;
import org.jsola.hr.service.ITemplateFieldService;
import org.jsola.hr.vo.TemplateFieldVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class TemplateFieldTestHelper extends BaseTestHelper {
    
    @Autowired
    private ITemplateFieldService templateFieldService;

    /**
     * 生成add测试数据
     * @return TemplateFieldAddDTO
     */
    public TemplateFieldAddDTO getTemplateFieldAddDTO(){
        TemplateFieldAddDTO templateFieldAddDTO = new TemplateFieldAddDTO();
        templateFieldAddDTO.setTemplateId(getRandomValue("varchar",32));
        templateFieldAddDTO.setField(getRandomValue("varchar",255));
        templateFieldAddDTO.setComment(getRandomValue("varchar",255));
        templateFieldAddDTO.setCompanyId(getRandomValue("varchar",32));
        return templateFieldAddDTO;
    }


    /**
     * 生成update测试数据
     * @return TemplateFieldUpdateDTO
     */
    public TemplateFieldUpdateDTO getTemplateFieldUpdateDTO(TemplateFieldVO templateFieldVO){
        return templateFieldService.selectDOById(templateFieldVO.getId(), SITE_ID).to(TemplateFieldUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return TemplateFieldQuery
     */
    public TemplateFieldQuery getTemplateFieldQuery() {
        TemplateFieldQuery templateFieldQuery = new TemplateFieldQuery();
        List<TemplateFieldDO> templateFieldDOList = templateFieldService.list(new TemplateFieldDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(templateFieldDOList)) {
            TemplateFieldDO templateFieldDO = templateFieldDOList.get(0);
            templateFieldQuery = templateFieldDO.to(TemplateFieldQuery.class);
            if (templateFieldDO.getGmtCreate() != null) {
                templateFieldQuery.setGmtCreateStart(DateKit.getBeforeDay(templateFieldDO.getGmtCreate(),-1));
                templateFieldQuery.setGmtCreateEnd(DateKit.getBeforeDay(templateFieldDO.getGmtCreate(),1));
            }
        }
        return templateFieldQuery;
    }

    /**
     * 保存示例
     * @return TemplateFieldVO
     */
    public TemplateFieldVO saveTemplateFieldExample(){
        TemplateFieldAddDTO addDTO = this.getTemplateFieldAddDTO();
        TemplateFieldVO templateFieldVO = templateFieldService.save(addDTO,buildTokenUser());
        return templateFieldVO;
    }


}

